<?php
include("common.inc.php");
InitGP(array("action","code","email","password","password2")); //初始化变量全局返回

if (!empty($code)) {
	@list($uname,$pwd,$email1) = explode("\t", cookie_authcode($code,'DECODE'));
	
	if (!empty($password) && !empty($password2)) {
		if (strlen($password)<=4) {
			showmessage("密碼長度太短！","-1",false);
		}
		if ($password!=$password2) {
			showmessage("兩次输入的密碼不一致！","-1",false);
		}
		include(INC_PATH."/member.class.php");
		$m=new memberclass();
		$info=$m->edit($uname,$email1,"",$password);
		if ($info=="OK") {
			showmessage("密碼修改成功！請登入！","login.php",true);
		}else {
			showmessage($info,"-1",false);
		}
		
	}
	if (empty($uname)) {
		showmessage("連結已過期！","index.php",false);
	}else {
		include template('resetpassword');//包含输出指定模板	
	}
	

}else {
	if (!empty($email) && isemail($email)) {
		include(INC_PATH."/member.class.php");
		$m=new memberclass();
		$value=$m->getonebyemail($email);
		if ($value!=false) {
			
			$string=$value['uname']."\t".$value['pwd']."\t".$value['email'];
			
			$codestring=cookie_authcode($string,'ENCODE',"",3600);
			@list($uname,$pwd,$email1) = explode("\t", cookie_authcode($codestring,'DECODE'));
			
			echo $uname.$pwd.$email1;
			echo $codestring;
			//exit;
			$subject="{$cfg_site_name} 重設密碼";
			//发送邮件操作
			$site=SITE_URL;
			
			$codestring=str_replace("+","%2B",$codestring);
			$emailstr="hi {$value['uname']},<BR><BR>您在{$cfg_site_name}申請了重設密碼，請點選下面的連結，然後根據頁面提示完成密碼重設：<BR><BR><BR><A href='{$site}/resetp.php?code={$codestring}' target=_blank>{$site}/resetp.php?code={$codestring}</A><BR><BR>-- <BR>{$cfg_site_name}";
			
			include_once(INC_PATH."/sendmail.class.php");
			$sendmail=new SendEmail();
			
			$sendmail->sendmailto($subject,$emailstr,$value['email']);
			
			showmessage("重設密碼郵件已經發送到您信箱！請登入您的註冊信箱，點選重設密碼連結修改密碼！","index.php",true);
			
		}else showmessage("email不存在！","-1",false);
		
	}
include template('resetp');//包含输出指定模板	
}

?>